<template>
  <el-radio-group v-model="isCollapse">
    <el-radio-button :label="false"
      ><el-icon> <Files /> </el-icon
    ></el-radio-button>
    <el-radio-button :label="true"
      ><el-icon> <FolderOpened /> </el-icon
    ></el-radio-button>
  </el-radio-group>
  <el-menu
    default-active="1-1"
    :collapse="isCollapse"
    @open="handleOpen"
    @close="handleClose"
  >
    <el-menu-item index="0">
      <el-icon>
        <Grid style="color: #409eff" />
      </el-icon>
      <template #title>
        <RouterLink to="/main/">首页</RouterLink>
      </template>
    </el-menu-item>

    <el-sub-menu index="1">
      <template #title>
        <el-icon>
          <Notebook style="color: #409eff" />
        </el-icon>
        <span>图书管理</span>
      </template>
      <el-menu-item index="1-1">
        <RouterLink to="/main/bookList">图书管理</RouterLink>
      </el-menu-item>
      <el-menu-item index="1-2" v-if="login.data.aid == 1">
        <RouterLink to="/main/borrowInfoList3">借阅管理</RouterLink>
      </el-menu-item>
      <el-menu-item index="1-2" v-if="login.data.aid == 1">
        <RouterLink to="/main/borrowInfoList2">借阅管理</RouterLink>
      </el-menu-item>
      <el-menu-item index="1-2" v-if="login.data.aid == 2">
        <RouterLink to="/main/borrowInfoList">借阅管理</RouterLink>
      </el-menu-item>
    </el-sub-menu>
    <el-menu-item index="2" v-if="login.data.aid == 1">
      <el-icon>
        <User style="color: #409eff" />
      </el-icon>
      <template #title>
        <RouterLink to="/main/userList">用户管理</RouterLink>
      </template>
    </el-menu-item>
    <el-menu-item index="3" v-if="login.data.aid == 1">
      <el-icon>
        <Grid style="color: #409eff" />
      </el-icon>
      <template #title>
        <RouterLink to="/main/permissionList">权限管理</RouterLink>
      </template>
    </el-menu-item>
    <el-menu-item index="4">
      <el-icon>
        <setting style="color: #409eff" />
      </el-icon>
      <template #title>关于</template>
    </el-menu-item>
  </el-menu>
</template>

<script setup>
import { ref, onBeforeMount, reactive } from "vue";
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
  Grid,
} from "@element-plus/icons-vue";

const isCollapse = ref(true);
const handleOpen = (key, keyPath) => {
  console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
  console.log(key, keyPath);
};
const login = reactive({});
onBeforeMount(() => {
  login.data = JSON.parse(sessionStorage.getItem("user"));

  console.log(login.data);
});
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
